﻿Imports System.Data.OleDb
Public Class ViewQuestionDetails
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            If Request.Params("ID") = "" Then Response.Redirect("List.aspx")
            Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionStringList").ConnectionString)
            Dim sqlString As String = "SELECT * from Question_Comments WHERE Q_FKID = @f1"
            Dim cmd As New OleDbCommand(sqlString, oleDbConn)
            oleDbConn.Open()
            cmd.CommandType = CommandType.Text
            cmd.Parameters.AddWithValue("@f1", Request.Params("ID"))
            Dim dataReader = cmd.ExecuteReader()
            'GridView1.DataSource = dataReader
            'GridView1.DataBind()

            Dim QuestionViewed As String = "INSERT INTO Question_View_Times (Author, Q_FKID) VALUES (@f1,@f2)"
            Dim ViewCmd As New OleDbCommand(QuestionViewed, oleDbConn)
            ViewCmd.CommandType = CommandType.Text
            ViewCmd.Parameters.AddWithValue("@f1", User.Identity.Name)
            ViewCmd.Parameters.AddWithValue("@f2", Request.Params("ID"))
            ViewCmd.ExecuteNonQuery()
            oleDbConn.Close()
        End If
    End Sub

    Protected Sub Btn_Submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Btn_Submit.Click
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionStringList").ConnectionString)
        Dim sqlString As String = "INSERT INTO Question_Comments(Q_FKID,Comments,Author,DateUpdated) VALUES(@f1,@f2,@f3,@f4)"

        Dim cmd As New OleDbCommand(sqlString, oleDbConn)
        oleDbConn.Open()
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", Request.Params("ID"))
        cmd.Parameters.AddWithValue("@f2", Tb_Answer.Text)
        cmd.Parameters.AddWithValue("@f2", User.Identity.Name)
        cmd.Parameters.AddWithValue("@f3", Convert.ToString(DateAndTime.Now))
        cmd.ExecuteNonQuery()
        oleDbConn.Close()
        Response.Redirect("ViewQuestionDetails.aspx?ID=" & Request.Params("ID"))
    End Sub

End Class